package btreegui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Bart
 */
public class DrawTreeElementBucket {

    private BTreeGUI frame;
    private List<DrawTreeElement> treeElementValues;
    private int anzahl = 0;
    private Dimension bLocation = new Dimension(0, 0);
    private Dimension bSize = new Dimension(0, 0);

    public DrawTreeElementBucket(BTreeGUI frame) {
        this.frame = frame;
        treeElementValues = new ArrayList<DrawTreeElement>();
    }

    public void addTreeElement(String treeValue, Color back, Color fore) {
        DrawTreeElement a = new DrawTreeElement(frame.getDrawTreePanel(), treeValue, anzahl, back, fore);
        treeElementValues.add(a);
        anzahl++;
    }

    public void drawBucket(Graphics2D g2d) {
        if (!treeElementValues.isEmpty()) {
            Rectangle2D rect = new Rectangle2D.Double(bLocation.width, bLocation.height, bSize.width - DrawTreeElement.getWidth(), bSize.height);
            g2d.setColor(Color.lightGray);
            for (int i = 1; i < (bSize.width / DrawTreeElement.getWidth() - 1); i++) {
                g2d.drawLine(bLocation.width + i * DrawTreeElement.getWidth(), bLocation.height, bLocation.width + i * DrawTreeElement.getWidth(), bLocation.height + DrawTreeElement.getHeight());
            }
            g2d.draw(rect);
        }
        for (DrawTreeElement drawTreeElement : treeElementValues) {
            drawTreeElement.paintComponent(g2d, getbLocation().width, getbLocation().height);
        }
    }

    public void ClearBucket() {
        treeElementValues.clear();
        anzahl = 0;
    }

    public void setbLocation(Dimension bLocation) {
        this.bLocation = bLocation;
    }

    public void setbSize(int k) {
        this.bSize = new Dimension(((k + 1) * DrawTreeElement.getWidth()), DrawTreeElement.getHeight());
    }

    public Dimension getbLocation() {
        return bLocation;
    }

    public Dimension getbSize() {
        return bSize;
    }

    public List<DrawTreeElement> getTreeElementValues() {
        return treeElementValues;
    }
}
